/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.mall.shopping.web.abc
   Module Description   :

   Date Created      : 2011/5/18
   Original Author   : feeling.wang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.mall.shopping.web;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Period;

import com.yaodian100.ec.order.entity.Orders;

/**
 * @author feeling.wang
 * 
 */
public class abc {

	public boolean isAfterPayDay(DateTime datetime) {
		if (datetime.getMonthOfYear() == 2) { // February is month 2!!
			return datetime.getDayOfMonth() > 26;
		}
		return datetime.getDayOfMonth() > 28;
	}

	public Days daysToNewYear(LocalDate fromDate) {
		LocalDate newYear = fromDate.plusYears(1).withDayOfYear(1);
		return Days.daysBetween(fromDate, newYear);
	}

	public boolean isRentalOverdue(DateTime datetimeRented) {
		Period rentalPeriod = new Period().withDays(2).withHours(12);

		// return datetimeRented.plus.plus(rentalPeriod).isBeforeNow();
		return false;
	}

	public String getBirthMonthText(LocalDate dateOfBirth) {
		return dateOfBirth.monthOfYear().getAsText(Locale.ENGLISH);
	}

	Map sortByValue(Map<String, Orders> map) {
		List<Orders> list = new LinkedList(map.entrySet());
		Collections.sort(list, new Comparator() {
			public int compare(Object o1, Object o2) {
				Orders order1 = (Orders) ((Map.Entry) (o1)).getValue();
				Orders order2 = (Orders) ((Map.Entry) (o2)).getValue();
				BigDecimal op1 = order1.getTotalPrice().subtract(order1.getDiscount());
				BigDecimal op2 = order2.getTotalPrice().subtract(order2.getDiscount());
				return op1.compareTo(op2);
			}
		});
		Map result = new LinkedHashMap();
		for (Iterator it = list.iterator(); it.hasNext();) {
			Map.Entry entry = (Map.Entry) it.next();
			result.put(entry.getKey(), entry.getValue());
		}
		return result;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(StringUtils.countMatches("Y", "NYNNY"));
		String aa = "y,m";
		System.out.println(aa.split(",")[1]);

		// BigDecimal price1 = new BigDecimal(102.819);
		// System.out.println("price1:" + price1.setScale(1, BigDecimal.ROUND_CEILING));
		// BigDecimal price2 = new BigDecimal(102.899);
		// System.out.println("price2:" + price2.setScale(1, RoundingMode.CEILING));

		// System.out.println(PRODUCT_TYPE.valueOf("EVENT"));
		// BigDecimal price = new BigDecimal(102.899);
		// System.out.println(price.setScale(1, RoundingMode.HALF_EVEN));
		//
		// System.out.println("DateTime");
		// System.out.println("=======");
		// System.out.println("DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally");
		// System.out.println("DateTime is immutable and thread-safe");
		// System.out.println("                      in = new DateTime()");
		// DateTime in = new DateTime();
		// System.out.println("Millisecond time:     in.getMillis():           " + in.getMillis());
		// System.out.println("ISO string version:   in.toString():            " + in.toString());
		// System.out.println("ISO chronology:       in.getChronology():       " + in.getChronology());
		// System.out.println("Your time zone:       in.getDateTimeZone():     " + in.getZone());
		// System.out.println("Change millis:        in.withMillis(0):         " + in.withMillis(0L));
		// System.out.println("");
		// System.out.println("Get year:             in.getYear():             " + in.getYear());
		// System.out.println("Get monthOfYear:      in.getMonthOfYear():      " + in.getMonthOfYear());
		// System.out.println("Get dayOfMonth:       in.getDayOfMonth():       " + in.getDayOfMonth());
		// System.out.println("...");
		// System.out.println("Property access:      in.dayOfWeek().get():                   " + in.dayOfWeek().get());
		// System.out.println("Day of week as text:  in.dayOfWeek().getAsText():             " +
		// in.dayOfWeek().getAsText());
		// System.out.println("Day as short text:    in.dayOfWeek().getAsShortText():        "
		// + in.dayOfWeek().getAsShortText());
		// System.out.println("Day in french:        in.dayOfWeek().getAsText(Locale.FRENCH):"
		// + in.dayOfWeek().getAsText(Locale.FRENCH));
		// System.out.println("Max allowed value:    in.dayOfWeek().getMaximumValue():       "
		// + in.dayOfWeek().getMaximumValue());
		// System.out.println("Min allowed value:    in.dayOfWeek().getMinimumValue():       "
		// + in.dayOfWeek().getMinimumValue());
		// System.out.println("Copy & set to Jan:    in.monthOfYear().setCopy(1):            " +
		// in.monthOfYear().setCopy(1));
		// System.out.println("Copy & add 14 months: in.monthOfYear().addCopy(14):           "
		// + in.monthOfYear().addToCopy(14));
		// System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14):  "
		// + in.monthOfYear().addWrapFieldToCopy(14));
		// System.out.println("...");
		// System.out.println("Convert to Instant:   in.toInstant():           " + in.toInstant());
		// System.out.println("Convert to DateTime:  in.toDateTime():          " + in.toDateTime());
		// System.out.println("Convert to MutableDT: in.toMutableDateTime():   " + in.toMutableDateTime());
		// System.out.println("Convert to Date:      in.toDate():              " + in.toDate());
		// System.out.println("Convert to Calendar:  in.toCalendar(Locale.UK): "
		// + in.toCalendar(Locale.UK).toString().substring(0, 46));
		// System.out.println("Convert to GregCal:   in.toGregorianCalendar(): "
		// + in.toGregorianCalendar().toString().substring(0, 46));
		// System.out.println("");
		// System.out.println("                      in2 = new DateTime(in.getMillis() + 10)");
		// DateTime in2 = new DateTime(in.getMillis() + 10);
		// System.out.println("Equals ms and chrono: in.equals(in2):           " + in.equals(in2));
		// System.out.println("Compare millisecond:  in.compareTo(in2):        " + in.compareTo(in2));
		// System.out.println("Compare millisecond:  in.isEqual(in2):          " + in.isEqual(in2));
		// System.out.println("Compare millisecond:  in.isAfter(in2):          " + in.isAfter(in2));
		// System.out.println("Compare millisecond:  in.isBefore(in2):         " + in.isBefore(in2));
		// System.out.println(in);
		// System.out.println(in.plus(Duration.standardDays(3l)));
		// System.out.println(in.minus(Period.months(2)));
		// System.out.println(25 / 2);
		// System.out.println(Integer.parseInt(String.valueOf(25 / 2)));
		// BigDecimal aa = new BigDecimal(419);
		// System.out.println(aa.setScale(0, RoundingMode.UP));
		//
		// System.out.println(aa.divide(new BigDecimal(2)).setScale(0, RoundingMode.DOWN).multiply(new BigDecimal(3)));
		//
		// BigDecimal a1 = new BigDecimal(32);
		// BigDecimal a2 = new BigDecimal(189);
		// BigDecimal a3 = new BigDecimal(236);
		// System.out.println(a1.divide(a2, 1, RoundingMode.DOWN).multiply(a3).setScale(0, RoundingMode.DOWN));

		// System.out.println((10 - 10) / 10);
		// Map<String, String> aa = new HashMap<String, String>();
		// aa.put("abc", "0,N");
		// String[] bbb = aa.values().toArray(new String[0]);
		// System.out.println(ArrayUtils.contains(bbb, "N"));

		// BigDecimal w = new BigDecimal(0);
		// BigDecimal h = new BigDecimal(60);
		// BigDecimal l = new BigDecimal(90);
		// BigDecimal volume = w.multiply(h).multiply(l);
		// System.out.println(volume.setScale(2, BigDecimal.ROUND_FLOOR));

		// Vector<String> ve = new Vector<String>();
		// ve.add("a");
		// ve.add("b");
		// System.out.println(ve.toString());
		//
		// List<String> list = new ArrayList<String>();
		// list.add("a");
		// list.add("b");
		// String listString = list.toString();
		// System.out.println(StringUtils.stripAll(list.toArray(new String[0]), "[]").toString());
		// System.out.println(listString.split(","));
		// BigDecimal p = new BigDecimal(0.9);
		// BigDecimal s = new BigDecimal(28.0);
		// BigDecimal d = new BigDecimal(10).divide(new BigDecimal(100));
		// BigDecimal a = new BigDecimal(108).multiply(d).setScale(0, RoundingMode.FLOOR);
		// System.out.println(a.subtract(new BigDecimal(11)).floatValue() < -1.0);
		// System.out.println(a);
		// System.out.println(p.compareTo(s) < 0);
		// System.out.println(p.floatValue() < s.floatValue());
		// BigDecimal qq = new BigDecimal(0.9).setScale(0, RoundingMode.UP);
		// System.out.println(qq.intValue());
		// BigDecimal qq2 = new BigDecimal(1.9).setScale(0, RoundingMode.UP);
		// System.out.println(qq2.intValue());
		// System.out.println(new BigDecimal(0.9).multiply(new BigDecimal(0.1)).setScale(0, RoundingMode.UP));
	}
}
